package com.baymax.test.scene

import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.util.Log
import kotlinx.coroutines.*

@OptIn(DelicateCoroutinesApi::class)
class PopReceiver : BroadcastReceiver(), CoroutineScope by MainScope() {


    var job: Job = Job()

    override fun onReceive(context: Context, intent: Intent) {
        Log.d("PopReceiver", "chinamobile onReceive: $context ,$intent ${intent.extras}")
        if (intent.action == "com.chinamobile.popup.remind") {
            job.cancel()
            job = launch() {
                repeat(3){
                    delay(2000)
                    val f = Intent()
                    f.action = "com.chinamobile.popup.tolauncher_reqshow"
                    f.putExtra("taskId", "1001")
                    context.sendBroadcast(f)
                    Log.d("PopReceiver", "chinamobile send f")
                }
            }

        } else if (intent.action == "com.chinamobile.popup.topersonal_show") {
            Log.d("PopReceiver", "chinamobile show dialog")
            job.cancel()
        }

    }
}